const app = getApp(),url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Nid:0,
    all_new:[
      {id:0,name:'全部',},{id:1,name:'被查看',},{id:2,name:'待沟通',},{id:4,name:'邀面试'},{id:3,name:'不适合',}
    ],
    listdata:[],
    where:{
      pageNum :0,
      pageSize :6,
      user_uid :'',
      apply_state:'',
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this
    var Nid = that.data.Nid
    if(Nid == 0){
      var urlapi = 'apply/getAllApplyPosition'
    }else{
      var urlapi = "apply/getPositionByApplyState"
    }
    var uid = wx.getStorageSync('user_massage')
    that.data.where.user_uid = uid.userUid
    that.data.where.apply_state = Nid
    that.data.where.pageNum ++
    var where = that.data.where
    wx.request({
      url:url+urlapi,
      header:{
        'context-type': 'application/json',
      },
      method: 'GET',
      data:where,
      success:function(res){
        console.log("where",res);
        var ret = res.data
        if(ret.code == 200){
            var listdata=ret.data.content
            that.setData({listdata})
        }else{
          that.setData({listdata:[]})
          // wx.showToast({
          //   title: ret.msg,
          //   icon:'none'
          // })
        }
      }
    })
  },
  toChat(e){
    let {index, item} = e.currentTarget.dataset;
    this.data.listdata[index].homeAddress = 0
    setTimeout(() => {
      this.setData({
        listdata: this.data.listdata
      })
    }, 1000);
    wx.navigateTo({
      url: '/pages/chat/chat?position='+ JSON.stringify(item),
    })
    return
  },
  //点击类别 全部  最新
  butType(e){
    let that = this
    let tid = e.currentTarget.dataset.id
    console.log(tid)
    that.setData({Nid:tid})
    that.data.where.pageNum = 0
    that.onLoad()
  },
  detail(e){
    var that = this
    let did = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/HomePage/workdetail/workdetail?id='+did,//+'&isColl='+isColl
    })
  },
  onReachBottom: function () {
    var that = this
      that.bottom()    
  },
  bottom(){
    var that = this
    var uid = wx.getStorageSync('user_massage')
    if(!uid){
      wx.showToast({
        title: '数据有误！',
        icon:'none',
      })
      return false
    }
    that.data.where.user_uid = uid.userUid
    that.data.where.pageNum ++
    var where = that.data.where
    var listdata = that.data.listdata
    /** 20210622 yanghl 解决全部已投职位加载问题 start */
    //var urlapi = "apply/getPositionByApplyState"//apply/getAllApplyPosition
    var Nid = that.data.Nid
    if (Nid == 0) {
      var urlapi = 'apply/getAllApplyPosition'
    } else {
      var urlapi = "apply/getPositionByApplyState"
    }
    /** 20210622 yanghl 解决全部已投职位加载问题 start */
    wx.request({
      url:url+urlapi,
      header:{
        'context-type': 'application/json',
      },
      method: 'GET',
      data:where,
      success:function(res){
        console.log("where",res);
        var ret = res.data
        if(ret.code == 200){
          if(ret.data.content != ''){
            listdata=listdata.concat(ret.data.content)
            that.setData({listdata})
          }else{
            wx.showToast({
              title: '没有数据了~',
              icon:'none'
            })
          }
        }else{
          wx.showToast({
            title: ret.msg,
            icon:'none'
          })
        }
      }
    })
  },
  onHide: function () {
    var that = this
    that.data.where.pageNum = 0
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    var that = this
    that.data.where.pageNum = 0
  },
})